// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:mybaseplus/base/abstract/IFFR.dart';
import 'package:mybaseplus/base/abstract/IFFRefresh.dart';
import 'package:mybaseplus/base/abstract/IFFScaffold.dart';
import 'package:mybaseplus/base/tool/language/FFMultiLanguage.dart';
import 'package:mybaseplus/base/widget/layout/FFNavi2.dart';
import 'package:mybaseplus/base/widget/layout/FFTextButton.dart';
import 'package:mybaseplus/base/widget/page/FFListScaffold.dart';
import 'package:mybaseplus/base/tool/extension/FFListExt.dart';
import 'package:mybaseplus_example/const/ImgConst.dart';
import 'package:mybaseplus_example/const/LgConst.dart';

class MultiLanguagePage extends FFListScaffold {
  String? name;

  MultiLanguagePage({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  MultiLanguagePageState createState() => MultiLanguagePageState();
}

class MultiLanguagePageState extends FFListScaffoldState {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  MultiLanguagePage get widget => super.widget as MultiLanguagePage;

  ///刷新控制
  @override
  IFFRefresh? get iffRefresh => refresh;
  late MultiLanguagePageStateRefresh refresh =
      MultiLanguagePageStateRefresh(state: this);

  @override
  FFPageSpacingParam? get ffPageSpacingParam =>
      FFPageSpacingParam(bottomSpacing: true);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNavi2.createNavi(
      context,
      title: LgConst.error(context),
      titleCenter: true,
      actions: [
        FFNavi2Action(
          type: FFNavi2ActionType.img,
          value: ImgConst.imgred1,
          onClick: () {},
        ),
      ],
    );
  }

  @override
  Widget ffItem(BuildContext context, int index) {
    LanguageConfigEntity entity = datas[index];
    return FFTextButton(
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 20),
      color: Colors.white,
      text: entity.languageName,
      fontColor: Colors.red,
      onClick: (){
        FFMultiLanguage.changeLanguage(entity.locale);
      },
    );
  }
}

class MultiLanguagePageStateRefresh with MFFRefresh {
  MultiLanguagePageState state;

  MultiLanguagePageStateRefresh({required this.state});

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    return R(rStatus: RStatus.result,data: FFMultiLanguage.supportedLocalesList);
  }
}
